package network

type ClientMgr struct {
	clients map[string]*Client
}

type Client struct {
	Ip       string //登陆Ip
	ID       string //用户id
	UserName string //用户名
	Password string //密码
	Channel  string //渠道 1 app 2 h5
}

var gClientMgr *ClientMgr

func init() {
	gClientMgr = new(ClientMgr)
	gClientMgr.clients = make(map[string]*Client, 100)

}

func (this *ClientMgr) GetInstance() *ClientMgr {
	return gClientMgr
}

func (this *ClientMgr) Insert(c *Client) bool {
	if _, ok := this.clients[c.ID]; ok {
		return false
	}
	this.clients[c.ID] = c
	return true
}

func (this *ClientMgr) Delete(c *Client) bool {
	if _, ok := this.clients[c.ID]; ok {
		delete(this.clients, c.ID)
		return true
	}
	return false
}

func (this *ClientMgr) GetClientById(id string) *Client {
	if v, ok := this.clients[id]; ok {
		return v
	}
	return nil
}
